% --------------------------------------------------------
% Copyright (c) Weiyang Liu, Yandong Wen
% Licensed under The MIT License [see LICENSE for details]
%
% Intro:
% Get a image list `$SPHEREFACE_ROOT/train/data/CASIA-WebFace-112X96.txt`,
% which is needed by caffe-sphereface
%
% Usage:
% cd $SPHEREFACE_ROOT/train
% run code/get_list.m
% --------------------------------------------------------

clear;clc;close all;
cd('../');

%folder    = fullfile(pwd, 'data/CASIA-WebFace-112X96');
%folder    = fullfile(pwd, 'data/my_data_new_all-112X96');
folder    = fullfile(pwd, 'data/my_testData-112X96');
orinSubFolder = struct2cell(dir(folder))';

% exclude the identities appearing in LFW dataset
% indx = ismember(subFolder, [{'0166921'}, {'1056413'}, {'1193098'}]);
% subFolder(indx) = [];

% create the list for trianing
for k = 1:5
  eachcls_num = k * 20;
  for l = 1:10
    cls_num         = l*20;
    filename    = sprintf('data/my_testData-112X96_%dcls_%dnum.txt', cls_num, eachcls_num);
    fid = fopen(filename, 'w');
    subFolder = orinSubFolder(3:3+cls_num-1, 1);
    for i = 1:length(subFolder)
      fprintf('Collecting the %dth folder (total %d) ...\n', i, length(subFolder));
      subList   = struct2cell(dir(fullfile(folder, subFolder{i}, '*.jpg')))';
      %fileNames = fullfile(folder, subFolder{i}, subList(:, 1));
      fileNames = fullfile(folder, subFolder{i}, subList(:, 1));
      subListLen= size(subList, 1);

      k_num   = min([subListLen, eachcls_num]);
      %for j = 1:length(fileNames)
      for j = 1:k_num
        fprintf(fid, '%s %d\n', fileNames{j}, i-1);
      end
    end
    fclose(fid);
  end
end
